package com.m4f.appengine.utils.security.authentication;

import java.util.Collection;
import java.util.HashSet;
import org.springframework.security.core.GrantedAuthority;
import com.m4f.appengine.utils.security.user.registry.AppUser;
import org.springframework.security.authentication.AbstractAuthenticationToken;

@SuppressWarnings("serial")
public class GaeUserAuthentication extends AbstractAuthenticationToken {
	
	private final AppUser principal;
	private Object credentials;
	
    public GaeUserAuthentication(AppUser principal, Object details, Object credentials) {
    	super((Collection<GrantedAuthority>) principal.getAuthorities());
        this.principal = principal;
        this.setDetails(details);
        this.setAuthenticated(true);
        this.credentials = credentials;
    }

    public Collection<GrantedAuthority> getAuthorities() {
        return new HashSet<GrantedAuthority>(principal.getAuthorities());
    }

  

    public Object getPrincipal() {
        return principal;
    }

    

    

    public String getName() {
        return principal.getUserId();
    }

    @Override
    public String toString() {
        return "GaeUserAuthentication{" +
                "principal=" + principal +
                ", details=" + this.getDetails() +
                ", authenticated=" + this.isAuthenticated() +
                '}';
    }

	@Override
	public Object getCredentials() {
		return this.credentials;
	}

	

}